//
//  CXAddAndDeletaView.m
//  GiftThat
//
//  Created by ChuXiang on 16/1/12.
//  Copyright © 2016年 ChuXiang. All rights reserved.
//

#import "CXAddAndDeletaView.h"
@interface CXAddAndDeletaView ()
@property (nonatomic, strong) UILabel *titleLabel;
@end

static BOOL isDelete = YES;
@implementation CXAddAndDeletaView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
        self.deleteButton.frame = CGRectMake(self.width / 2 + self.width / 4, 0, self.width / 4, self.height);
        [self.deleteButton setTitle:@"排序或删除" forState:UIControlStateNormal];
        [self.deleteButton.titleLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:12]];
        [self.deleteButton setTintColor:[UIColor colorWithRed:255 / 255.0 green:38 / 255.0 blue:56 / 255.0 alpha:1.0]];
        
        [self.deleteButton addTarget:self action:@selector(deleteButtonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.deleteButton];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.width / 19, 0, self.width / 6, self.height)];
        self.titleLabel.text = @"切换频道";
        [self.titleLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:12]];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLabel];
    }
    
    return self;
}

- (void)deleteButtonDidPress:(UIButton *)sender {
    isDelete = !isDelete;

    if (isDelete) {
        [self.deleteButton setTitle:@"完成" forState:UIControlStateNormal];
        self.titleLabel.text = @"拖动排序";
    }else {
        [self.deleteButton setTitle:@"排序或删除" forState:UIControlStateNormal];
        self.titleLabel.text = @"切换频道";
    }
    self.block(isDelete);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
